package redis

import (
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	"weekly1/user-server/nacos"
)

var Client redis.Client

func RedisInit() {
	nac := nacos.Config.Redis
	client := redis.NewClient(&redis.Options{
		Addr:     nac.Addr,
		Password: nac.Password, // no password set
		DB:       nac.DB,       // use default DB
	})

	pong, err := client.Ping(context.Background()).Result()
	if err != nil {
		fmt.Println("redis链接失败")
		return
	}
	fmt.Println("redis链接成功")
	fmt.Println(pong, err)
	// Output: PONG <nil>
}
